import "package:flutter/material.dart";

// 自定义dialog弹窗
class UseDialog extends Dialog {
  final String title; //标题
  final String content; //内容
  final Function()? onClose; //关闭
  final Function()? onEnter; //确认
  final Function()? onCancel; //取消
  const UseDialog(
      {super.key,
      required this.title,
      required this.content,
      this.onClose,
      this.onEnter,
      this.onCancel});
  @override
  Widget build(BuildContext context) {
    return Material(
      //Material 的子元素会占满整个屏幕
      type: MaterialType.transparency, //背景透明（默认白色），使透明背景点击关闭弹窗
      child: Center(
        //加上方位容器可以
        child: Container(
          width: 250,
          height: 200,
          decoration: const BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.all(Radius.circular(10))),
          child: Column(
            children: [
              Padding(
                padding: const EdgeInsets.fromLTRB(20, 10, 20, 5),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Text(title),
                    InkWell(
                      onTap: onClose,
                      child: const Icon(Icons.close),
                    )
                  ],
                ),
              ),
              Expanded(
                flex: 1,
                child: Padding(
                  padding: const EdgeInsets.all(20),
                  child: Center(
                    child: Text(content),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    TextButton(onPressed: onEnter, child: const Text('确认')),
                    TextButton(onPressed: onCancel, child: const Text('取消'))
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
